import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Counting {
  private int n,d;
  private int getDigitCount(){
      int a = 1; int b = (d==0)?9:8;
      for(int i=1 ; ;++i){
         if(n-b*a<=0) return i;
         n -= b*a; a = a*9;
      }
  }
  private int getPower(int a,int p){
     int r = 1;
     for(int i=1;i<=p;++i) r = r*a; return r;
  }
  private void run() throws Exception {
     BufferedReader bf = new BufferedReader( new
                              InputStreamReader(System.in));
     StringTokenizer st = new StringTokenizer(bf.readLine());
     n = Integer.parseInt(st.nextToken());
     d = Integer.parseInt(st.nextToken());
     int dcount = getDigitCount();
     int a = getPower(9,dcount-1); 
     for(int i=1;i<=dcount;++i){
        for(int j=0;j<=9;++j) 
           if(j==d || (i==1 && d!=0 && j==0) ) continue; 
           else {
              if(n-a<=0) { 
                 System.out.print(j); break; 
              }
              n -= a;    
           }  
         a = a/9; 
     }
     System.out.println("");
     return ;
  }
 public static void main(String [] Args) throws Exception {
     new Counting().run();
  }
}
